package com.csk.zsk.compents.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.csk.zsk.commons.action.AjaxActionSupport;
import com.csk.zsk.commons.utils.encode.JsonBinder;
import com.csk.zsk.commons.utils.web.struts2.Struts2Utils;
import com.csk.zsk.compents.entity.Comic;
import com.csk.zsk.compents.entity.ComicChapters;
import com.csk.zsk.compents.entity.ComicPages;
import com.csk.zsk.compents.service.ComicService;
@Controller
@Scope("prototype")
public class ComicAction extends AjaxActionSupport {

	private static final long serialVersionUID = 4791564409727560506L;
	private static JsonBinder binder = JsonBinder.buildNonDefaultBinder();
	@Autowired
	private ComicService comicService;
	
	private String comicId;
	private String comicLikeName;
	private String comicChaptersId;
	private String comicPagesId;
	private String startIndex;
	
	
	public String getComicId() {
		return comicId;
	}


	public void setComicId(String comicId) {
		this.comicId = comicId;
	}


	public String getComicChaptersId() {
		return comicChaptersId;
	}


	public void setComicChaptersId(String comicChaptersId) {
		this.comicChaptersId = comicChaptersId;
	}


	public String getComicPagesId() {
		return comicPagesId;
	}


	public void setComicPagesId(String comicPagesId) {
		this.comicPagesId = comicPagesId;
	}

	public String getComicLikeName() {
		return comicLikeName;
	}


	public void setComicLikeName(String comicLikeName) {
		this.comicLikeName = comicLikeName;
	}


	public String getStartIndex() {
		return startIndex;
	}


	public void setStartIndex(String startIndex) {
		this.startIndex = startIndex;
	}


	/**
	 * 获取漫画对象
	 */
	public void getComicToJsonById(){
		if(comicId==null||comicId.equals("")){
			return;
		}
		Comic comic = comicService.searchComicById(comicId);
		String json = binder.toJson(comic);
		Struts2Utils.renderJson(json);
	}
	/**
	 * 通过名字获取漫画列表
	 */
	public void getComicListToJsonByLikeName(){
		if(comicLikeName==null||comicLikeName.equals("")){
			return;
		}
		List<Comic> comicList = comicService.searchComicByLikeName(comicLikeName);
		String json = binder.toJson(comicList);
		Struts2Utils.renderJson(json);
	}
	/**
	 * 获取漫画章节列表
	 */
	public void getComicChaptersListToJsonByComicId(){
		if(comicId==null||comicId.equals("")){
			return;
		}
		Comic comic = comicService.searchComicById(comicId);
		
		String json = binder.toJson(comic.getComicChaptersList());
		Struts2Utils.renderJson(json);
	}
	/**
	 * 获取漫画章节对象
	 */
	public void getComicChaptersToJsonById(){
		if(comicChaptersId==null||comicChaptersId.equals("")){
			return;
		}
		ComicChapters comicChapters = comicService.searchComicChaptersById(comicChaptersId);
		String json = binder.toJson(comicChapters);
		Struts2Utils.renderJson(json);
	}
	/**
	 * 获取漫画章节页面列表
	 */
	public void getComicPagesListToJsonByComicChaptersId(){
		if(comicChaptersId==null||comicChaptersId.equals("")){
			return;
		}
		ComicChapters comicChapters = comicService.searchComicChaptersById(comicChaptersId);
		String json = binder.toJson(comicChapters.getComicPagesList());
		Struts2Utils.renderJson(json);
	}
	/**
	 * 获取漫画页面对象
	 */
	public void getComicPagesToJsonById(){
		if(comicPagesId==null||comicPagesId.equals("")){
			return;
		}
		ComicPages comicPages = comicService.searchComicPagesById(comicPagesId);
		String json = binder.toJson(comicPages);
		Struts2Utils.renderJson(json);
	}
	/**
	 * 获取排名前10的漫画
	 */
	public void searchTop10ByOrder(){
		if(startIndex==null||startIndex.equals("")){
			startIndex = "0";
		}
		List<Comic> comicList = comicService.searchTop10ByOrder(startIndex);
		String json = binder.toJson(comicList);
		Struts2Utils.renderJson(json);
		
	}
	/**
	 * 获取推荐前10的漫画
	 */
	public void searchTop10ByRec(){
		if(startIndex==null||startIndex.equals("")){
			startIndex = "0";
		}
		List<Comic> comicList = comicService.searchTop10ByRec(startIndex);
		String json = binder.toJson(comicList);
		Struts2Utils.renderJson(json);
	}
	/**
	 * 获取随机前10的漫画
	 */
	public void searchTop10ByRandom(){
		List<Comic> comicList = comicService.searchTop10ByRandom();
		String json = binder.toJson(comicList);
		Struts2Utils.renderJson(json);
	}
	
	
}
